/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
#ifndef _POSITION_FILE_WRITER_HPP
#define _POSITION_FILE_WRITER_HPP

#include "owndebug.h"
#include <string>
#include "PositionData.hpp"
struct TPositionLogLine{

  TPositionLogLine(unsigned int aTimestamp_s = 0,
                   unsigned int aTimestamp_us = 0,
                   float aPositionX = 0.0,
                   float aPositionY = 0.0,
                   float aHeading = 0.0,
                   float aVarianceX = 0.0,
                   float aVarianceY = 0.0,
                   float aVarianceHeading = 0.0,
                   float aProbability = 0.0,
                   float aSpeed = 0.0,
                   float aAngularSpeed = 0.0)
    :timestamp_s(aTimestamp_s),
     timestamp_us(aTimestamp_us),
     positionX(aPositionX),
     positionY(aPositionY),
     heading(aHeading),
     varianceX(aVarianceX),
     varianceY(aVarianceY),
     varianceHeading(aVarianceHeading),
     probability(aProbability),
     speed(aSpeed),
     angularSpeed(aAngularSpeed){}
  
  unsigned int timestamp_s;
  unsigned int timestamp_us;
  float positionX;
  float positionY;
  float heading;
  float varianceX;
  float varianceY;
  float varianceHeading;
  float probability;
  float speed;
  float angularSpeed;
};

struct TPosition3DLogLine{

  TPosition3DLogLine(unsigned int aTimestamp_s = 0,
                     unsigned int aTimestamp_us = 0,
                     float aPositionX = 0.0,
                     float aPositionY = 0.0,
                     float aPositionZ = 0.0,
                     float aAngleX = 0.0,
                     float aAngleY = 0.0,
                     float aAngleZ = 0.0,
                     float aVarianceX = 0.0,
                     float aVarianceY = 0.0,
                     float aVarianceZ = 0.0,
                     float aVarianceAngleX = 0.0,
                     float aVarianceAngleY = 0.0,
                     float aVarianceAngleZ = 0.0,
                     float aProbability = 0.0,
                     float aSpeed = 0.0,
                     float aAngularSpeed = 0.0)
    :timestamp_s(aTimestamp_s),
     timestamp_us(aTimestamp_us),
     positionX(aPositionX),
     positionY(aPositionY),
     positionZ(aPositionZ),
     angleX(aAngleX),
     angleY(aAngleY),
     angleZ(aAngleZ),
     varianceX(aVarianceX),
     varianceY(aVarianceY),
     varianceZ(aVarianceZ),
     varianceAngleX(aVarianceAngleX),
     varianceAngleY(aVarianceAngleY),
     varianceAngleZ(aVarianceAngleZ),
     probability(aProbability),
     speed(aSpeed),
     angularSpeed(aAngularSpeed){}
  
  unsigned int timestamp_s;
  unsigned int timestamp_us;
  float positionX;
  float positionY;
  float positionZ;
  float angleX;   ///< angle around x-axis
  float angleY;   ///< angle around y-axis
  float angleZ;   ///< angle around z-axis
  float varianceX;
  float varianceY;
  float varianceZ;
  float varianceAngleX;
  float varianceAngleY;
  float varianceAngleZ;
  float probability;
  float speed;
  float angularSpeed;
};

class CPositionFileWriter{
public:
  /**
   * Constructor
   */
  CPositionFileWriter();

  /**
   * Destructor
   */
  ~CPositionFileWriter();

  /**
   * Opens file with wanted filename
   */
  void OpenFile(std::string aFileName,
                std::string aMaCIGroup,
                std::string aInstanceName);

  /**
   * Closes the file
   */
  void CloseFile();

  /**
   * Writes a line of 2Dposition information. Use this if you have 2D
   * position information. 
   *
   * @param[in]    position information structure which have a measurement
   * @return       true if line succesfully writed (==file opened)
   */
  bool WriteLine(TPositionLogLine aLine);

  /**
   * Writes a line of 3D position information
   * Use this if you have 3D position information.
   *
   * @param[in]    position information structure which have a measurement
   * @return       true if line succesfully writed (==file opened)
   */
  bool WriteLine(TPosition3DLogLine aLine);
  /**
   * Writes a line of position information from the data got as
   * a position event
   *
   * param[in]     Position data container got as a position event
   * return        true if line succesfully writed (==file opened)
   */
  bool WriteLine(MaCI::Position::CPositionData &aData);
private:
  FILE *iFile;

  CPositionFileWriter(const CPositionFileWriter&)
    :iFile(NULL){}

  CPositionFileWriter &operator=(const  CPositionFileWriter&){return *this;}

};
#endif ///< _POSITION_FILE_WRITER_HPP
